Sinclair BASIC
   HOME

TheInfoList



OR:

Sinclair BASIC is a
dialect The term dialect (from Latin , , from the Ancient Greek word , 'discourse', from , 'through' and , 'I speak') can refer to either of two distinctly different types of Linguistics, linguistic phenomena: One usage refers to a variety (linguisti ...
of the programming language
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
used in the
8-bit In computer architecture, 8-bit Integer (computer science), integers or other Data (computing), data units are those that are 8 bits wide (1 octet (computing), octet). Also, 8-bit central processing unit (CPU) and arithmetic logic unit (ALU) arc ...
home computers from
Sinclair Research Sinclair Research Ltd is a British consumer electronics company founded by Clive Sinclair in Cambridge. It was originally incorporated in 1973 as Westminster Mail Order Ltd, renamed Sinclair Instrument Ltd, then Science of Cambridge Ltd, the ...
and
Timex Sinclair Timex Sinclair was a joint venture established in December 1982 between the British company Sinclair Research and Timex Corporation in an effort to gain an entry into the rapidly growing early-1980s home computer market in North America. His ...
. The Sinclair BASIC interpreter was made by Nine Tiles Networks Ltd.


History

Sinclair BASIC was originally developed in 1979 for the
ZX80 The Sinclair ZX80 is a home computer launched on 29 January 1980 by Science of Cambridge Ltd. (later to be better known as Sinclair Research). It is notable for being one of the first computers available in the United Kingdom for less than a h ...
by Nine Tiles. The programmers were John Grant, the owner of Nine Tiles, and Steve Vickers. It was initially an incomplete implementation of the 1978
American National Standards Institute The American National Standards Institute (ANSI ) is a private non-profit organization that oversees the development of voluntary consensus standards for products, services, processes, systems, and personnel in the United States. The organi ...
(ANSI) minimal BASIC standard with integer arithmetic only, termed the 4K BASIC (for its ROM size) for the ZX80. It evolved through the floating-point 8K BASIC for the
ZX81 The ZX81 is a home computer that was produced by Sinclair Research and manufactured in Dundee, Scotland, by Timex Corporation. It was launched in the United Kingdom in March 1981 as the successor to Sinclair's ZX80 and designed to be a low-cos ...
and
TS1000 The Timex Sinclair 1000 (or T/S 1000) was the first computer produced by Timex Sinclair, a joint venture between Timex Group USA, Timex Corporation and Sinclair Research. It was launched in July 1982, with a US sales price of US$99.95, making it t ...
(which was also available as an upgrade for the ZX80), and became an almost complete version in the 16 KB ROM
ZX Spectrum The ZX Spectrum () is an 8-bit computing, 8-bit home computer that was developed by Sinclair Research. It was released in the United Kingdom on 23 April 1982, and became Britain's best-selling microcomputer. Referred to during development as t ...
(known as 48K BASIC). It is present in all ZX Spectrum compatibles, with more advanced systems also offering expanded versions like 128K BASIC, +3 BASIC, T/S 2000 BASIC, BASIC64 or Timex Extended Basic. As of 2015, interpreters exist for modern operating systems, and older systems, that allow Sinclair Basic to be used easily.


Syntax

New BASIC programmers might start with a simple program, perhaps using the language's PRINT statement to display a message on the screen; a well-known and often-replicated example is Kernighan and Ritchie's
Hello world program ''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich ...
: 10 PRINT "Hello, World!"


Keywords

On the 16K/48K ZX Spectrum (48K BASIC), there are 88 keywords in Sinclair BASIC, denoting commands (of which there are 50), functions and logical operators (31), and other keywords (16, including 9 which are also commands or functions):


Keyword entry

In 48K models and older, the keywords are entered via Sinclair's unique keyword entry system, as indicated on the table. The most common commands need one keystroke only; for example, pressing only at the start of a line on a Spectrum produces the full command PRINT. Less frequent commands require more complex key sequences: BEEP (for example) is keyed by pressing plus to access extended mode (later models include an key), keeping held down and pressing . Keywords are colour-coded on the original Spectrum keyboard to indicate which mode is required: * : key only * on the key itself: plus the key * above the key: followed by the key * below the key: followed by plus the key The ZX81 8K BASIC used the shorter forms GOTO, GOSUB, CONT and RAND, whereas the Spectrum used the longer forms GO TO, GO SUB, CONTINUE and RANDOMIZE. The ZX80 4K BASIC also used these longer forms but differed by using the spelling RANDOMISE. The ZX81 8K BASIC was the only version to use FAST, SCROLL, SLOW and UNPLOT. The ZX80 4K BASIC had the exclusive function TL$(); it was equivalent to the string operator in later versions. Unique code points are assigned in the
ZX80 character set The ZX80 character set is the character encoding used by the Sinclair Research ZX80 microcomputer with its original 4K BASIC ROM. The encoding uses one byte per character for 256 code points. It has no relationship with previously established one ...
,
ZX81 character set The ZX81 character set is the character encoding used by the Sinclair Research ZX81 family of microcomputers including the Timex Sinclair 1000 and Timex Sinclair 1500. The encoding uses one byte per character for 256 code points. It has no rel ...
and
ZX Spectrum character set The ZX Spectrum character set is the variant of ASCII used in the ZX Spectrum family computers. It is based on ASCII-1967 but the characters ^, ` and DEL are replaced with ↑, £ and ©. It also differs in its use of the C0 control codes other ...
for each keyword or multi-character operator, i.e. <=, >=, <>, "" (tokenized on the ZX81 only), ** (replaced with on the Spectrum). These are expanded by referencing a token table in ROM. Thus, a keyword uses one byte of memory only, a significant saving over traditional letter-by-letter storage. This also meant that the
BASIC interpreter A BASIC interpreter is an interpreter that enables users to enter and run programs in the BASIC language and was, for the first part of the microcomputer era, the default application that computers would launch. Users were expected to use the BAS ...
could quickly determine any command or function by evaluating one byte, and that the keywords need not be ''reserved words'' like in other BASIC dialects or other programming languages, e.g., it is allowed to define a variable named PRINT and output its value with PRINT PRINT. This is also related to the syntax requirement that every line start with a command keyword, and pressing the one keypress for that command at the start of a line changes the editor from command mode to letter mode. Thus, variable assignment requires LET (i.e., LET a=1 not only a=1). This practice is also different from other BASIC dialects. Further, it meant that unlike other BASIC dialects, the interpreter needed no parentheses to identify functions; SIN x was sufficient, no SIN(x) needed (though the latter was allowed). The 4K BASIC ROM of the ZX80 had a short list of exceptions to this: the functions CHR$(), STR$(), TL$(), PEEK(), CODE(), RND(), USR() and ABS() did not have one-byte tokens but were typed in letter-by-letter and required the parentheses. They were listed as the INTEGRAL FUNCTIONS on a label above and to the right of the keyboard. The 128K Spectrum models, the ZX Spectrum 128, +2, +3, +2A, and +2B, also stored keywords internally in one-byte code points, but used a conventional letter-by-letter BASIC input system. They also introduced two new commands: * PLAY, which operated the 128k models'
General Instrument AY-3-8910 The AY-3-8910 is a 3-voice programmable sound generator (PSG) designed by General Instrument in 1978, initially for use with their 16-bit CP1610 or one of the PIC1650 series of 8-bit microcomputers. The AY-3-8910 and its variants were used i ...
music chip * SPECTRUM, which switched the 128k Spectrum into a 48k Spectrum compatibility mode The original Spanish ZX Spectrum 128 included four additional commands in Spanish, one of which was undocumented. These can be translated as: * EDIT (to edit a line number or invoke the full screen string editor) * RENUM (to renumber the program lines) * DELETE (to delete program lines) * WIDTH (to set the column width of the
RS-232 In telecommunications, RS-232 or Recommended Standard 232 is a standard originally introduced in 1960 for serial communication transmission of data. It formally defines signals connecting between a ''DTE'' (''data terminal equipment'') such a ...
device, but undocumented as the code was broken) Unlike the LEFT$(), MID$() and RIGHT$() functions used in the ubiquitous
Microsoft BASIC Microsoft BASIC is the foundation software product of the Microsoft company and evolved into a line of BASIC interpreters and compiler(s) adapted for many different microcomputers. It first appeared in 1975 as Altair BASIC, which was the first ve ...
dialects for home computers, parts of strings in Sinclair BASIC are accessed by numeric range. For example, gives a substring starting with the 5th and ending with the 10th character of the variable a$. Thus, it is possible to replace the LEFT$() and RIGHT$() commands by simply omitting the left or right array position respectively; for example is equivalent to LEFT$(a$,5). Further, a$(5) alone is enough to replace MID$(a$,5,1).


Variable names

Variables holding numeric values may be any length, while string and array variable names must consist of only one alphabetical character. Thus, LET a=5, LET Apples=5, LET a$="Hello", DIM a(10) and DIM a$(10) are all good, while LET Apples$="Fruit", DIM Apples(10) and DIM Apples$(10) are not. The long variable names allowed for numeric variables can include alphanumeric characters after the first character, so LET a0=5 is allowed but not LET 0a=5. The long variable names can also include spaces, which are ignored, so LET number of apples = 5 is the same as LET numberofapples = 5


Official versions


4K BASIC

*''4K BASIC'' for ZX80 (so named for residing in 4 
KiB The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit ...
read-only memory Read-only memory (ROM) is a type of non-volatile memory used in computers and other electronic devices. Data stored in ROM cannot be electronically modified after the manufacture of the memory device. Read-only memory is useful for storing sof ...
(ROM)), was developed by John Grant of Nine Tiles for the ZX80. It has integer-only arithmetic. **System Commands: NEW RUN LIST LOAD SAVE **Control Statements: GOTO IF THEN GOSUB STOP RETURN FOR TO NEXT CONTINUE **Input/Output Statements: PRINT INPUT **Assignment Statement: LET **Other Statements: CLEAR CLS DIM REM RANDOMIZE POKE


8K BASIC

* ''8K BASIC'' is the ZX81 BASIC (also available as an upgrade for the ZX80), updated with floating-point arithmetic by Steve Vickers, so named for residing in 8 KiB ROM. **Statements: PRINT RAND LET CLEAR RUN LIST GOTO CONT INPUT NEW REM PRINT STOP BREAK IF STOP FOR NEXT TO STEP SLOW FAST GOSUB RETURN SAVE LOAD CLS SCROLL PLOT UNPLOT PAUSE LPRINT LLIST COPY DIM POKE NEW **Functions: ABS SGN SIN COS TAN ASN ACS ATN LN EXP SQR INT PI RND FUNCTION LEN VALSTR$ NOT CODE CHR$ INKEY$ AT TAB INKEY$ PEEK USR


48 BASIC

* ''48 BASIC'' is the BASIC for the original 16/48 kB
RAM Ram, ram, or RAM may refer to: Animals * A male sheep * Ram cichlid, a freshwater tropical fish People * Ram (given name) * Ram (surname) * Ram (director) (Ramsubramaniam), an Indian Tamil film director * RAM (musician) (born 1974), Dutch * ...
ZX Spectrum (and clones), with colour and more peripherals added by Steve Vickers and John Grant. It resides in 16 KiB ROM and began to be called 48 BASIC with the introduction of the ZX Spectrum 128 at which time the 16 kB Spectrum was no longer sold and most existing ones in use had been upgraded to 48 kB


128 BASIC

* ''128 BASIC'' is the BASIC for the ZX Spectrum 128. It offers extra commands and uses letter-by-letter input. **New commands: LOAD ! SAVE ! MERGE ! ERASE PLAY


+3 BASIC

* ''+3 BASIC'' is the BASIC with disk support for the ZX Spectrum +3 and +2A. **New commands: FORMAT COPY


T/S 2000 BASIC

* ''T/S 2000 BASIC'' is used on the Spectrum-compatible
Timex Sinclair 2068 The Timex Sinclair 2068 (T/S 2068), released in November 1983, was Timex Sinclair's third and last home computer for the United States market. It was also marketed in Canada, Argentina, Portugal and Poland, as Timex Computer 2068 (TC 2068). Hi ...
(T/S 2068) and adds the following six new keywords: ** DELETE deletes BASIC program line ranges. ** FREE is a function that gives the amount of free RAM. PRINT FREE will show how much RAM is free. ** ON ERR is an error-handling function mostly used as ON ERR GO TO or ON ERR CONT. ** RESET can be used to reset the behaviour of ON ERR. It was also intended to reset peripherals. ** SOUND controls the AY-3-8192 sound chip. ** STICK is a function that gives the position of the internal joystick (Timex Sinclair 2090).


BASIC64

* ''BASIC64'' by Timex of Portugal, is a software extension to allow better Basic programming with the 512×192 and dual display areas graphic modes available only on
Timex Sinclair Timex Sinclair was a joint venture established in December 1982 between the British company Sinclair Research and Timex Corporation in an effort to gain an entry into the rapidly growing early-1980s home computer market in North America. His ...
computers. This extension adds commands and does a complete memory remap to avoid the system overwriting the extended screen memory area. Two versions exist due to different memory maps - a version for TC 2048 and a version for T/S 2068 and TC 2068. **PRINT # Prints to a specific output channel. **LIST # Lists the program to a specific output channel. **CLS* Clears both display areas. **INK* Sets ink colour for both display areas **PAPER* Sets paper colour both display areas **SCREEN$ Selects the high / normal resolution modes. **PLOT* Plots a pixel and updates the drawing position. **LINE Draws a line from the previous PLOT position, supporting arc drawing **CIRCLE* Draws a circle or oval, depending on screen mode.


Timex Extended Basic

* ''Timex Extended Basic'' by Timex of Portugal is used on the
Timex Computer 3256 The TC 3256 or Timex Computer 3256 was a 1987 computer created by Timex of Portugal, a branch of Timex Corporation. It was a third generation Sinclair ZX Spectrum compatible computer, with expanded capabilities and new ''TEC - Timex Extended Com ...
, adding ''TEC - Timex Extended Commands'' commands supporting the AY-3-8912 sound chip, RS-232 network and the 512x192 pixel high resolution graphic mode. **RAM drive commands: LOAD! SAVE! CAT! MERGE! ERASE! CLEAR! **RS-232 commands: FORMAT! LPRINT LLIST **AY-3-8912 commands: BEEP! **512x192 resolution commands: SCREEN$ DRAW! PLOT! CIRCLE!


Other versions, extensions, derivatives and successors


Interpreters for the ZX Spectrum family

Several ZX Spectrum interpreters exist. * '' Beta BASIC'' by Dr. Andy Wright, was originally a BASIC extension, but became a full interpreter. * '' YS MegaBasic'' by Mike Leaman. * '' ZebraOS'' by Zebra Systems in New York, a cartridge version of T/S 2000 BASIC that used the 512×192 screen mode. *
Sea Change ROM
' by Steve Vickers and Ian Logan, modified by Geoff Wearmouth, a replacement ROM with an enhanced Sinclair BASIC. *'' Gosh Wonderful'' by Geoff Wearmouth, a replacement ROM that fixes bugs and adds a tokenizer, stream lister, delete and renumber commands. * '' OpenSE BASIC'' (formerly SE BASIC) by Andrew Owen, a replacement ROM with bug fixes and many enhancements including ULAplus support, published as open source in 2011


Compilers for the ZX Spectrum family

Several ZX Spectrum compilers exist. * ''
HiSoft HiSoft Technology International Limited was a multinational information technology and business process outsourcing company headquartered in Dalian, China. Founded in 1996, HiSoft was listed on the NASDAQ public exchange in 2010. In November 2 ...
COLT Compiler'' (a.k.a. HiSoft COLT Integer Compiler) * ''
HiSoft HiSoft Technology International Limited was a multinational information technology and business process outsourcing company headquartered in Dalian, China. Founded in 1996, HiSoft was listed on the NASDAQ public exchange in 2010. In November 2 ...
BASIC'' (a.k.a. HiSoft BASIC Compiler), an integer and floating-point capable compiler * ''Laser Compiler'' * ''Softek 'IS' Integer Compiler'' (successor to Softek Integer Compiler) * ''Softek 'FP' Full Compiler'' * ''ZIP Compiler''


Derivatives and successors for other computers

* ''
SuperBASIC SuperBASIC is an advanced variant of the BASIC programming language with many structured programming additions. It was developed at Sinclair Research by Jan Jones during the early 1980s. Originally SuperBASIC was intended as the BASIC interprete ...
'', a much more advanced BASIC dialect introduced with the
Sinclair QL The Sinclair QL (for ''Quantum Leap'') is a personal computer launched by Sinclair Research in 1984, as an upper-end counterpart to the ZX Spectrum. The QL was aimed at the serious home user and professional and executive users markets from small ...
personal computer, with some similarities to the earlier Sinclair BASICs * ''SAM Basic'', the BASIC on the
SAM Coupé Sam, SAM or variants may refer to: Places * Sam, Benin * Sam, Boulkiemdé, Burkina Faso * Sam, Bourzanga, Burkina Faso * Sam, Kongoussi, Burkina Faso * Sam, Iran * Sam, Teton County, Idaho, United States, a populated place People and fictional ...
, generally considered a ZX Spectrum clone * ''ROMU6'' by Cesar and Juan Hernandez - MSX * ''Spectrum 48'' by Whitby Computers -
Commodore 64 The Commodore 64, also known as the C64, is an 8-bit home computer introduced in January 1982 by Commodore International (first shown at the Consumer Electronics Show, January 7–10, 1982, in Las Vegas). It has been listed in the Guinness ...
* ''Sparky eSinclair BASIC'' by Richard Kelsh, an operating system loosely based on ZX Spectrum BASIC -
Zilog eZ80 The Zilog eZ80 is an 8-bit microprocessor from Zilog, introduced in 2001. eZ80 is an updated version of the company's first product, the Zilog Z80, Z80 microprocessor. Design The eZ80 (like the Z380) is binary compatible with the Z80 and Z1 ...
* ''Sinbas'' by Pavel Napravnik -
DOS DOS is shorthand for the MS-DOS and IBM PC DOS family of operating systems. DOS may also refer to: Computing * Data over signalling (DoS), multiplexing data onto a signalling channel * Denial-of-service attack (DoS), an attack on a communicat ...
* ''Basic'' (and CheckBasic) by Philip Kendall -
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
* ''BINSIC'' by Adrian McMenamin, a reimplementation in
Groovy ''Groovy'' (or, less commonly, ''groovie'' or ''groovey'') is a slang colloquialism popular during the 1950s, '60s and '70s. It is roughly synonymous with words such as "excellent", "fashionable", or "amazing", depending on context. History The ...
closely modelled on ZX81 BASIC - Java * ''BASin'' by Paul Dunn, a complete Sinclair BASIC
integrated development environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools a ...
(IDE) based on a ZX Spectrum emulator - Windows * '' SpecBAS'' (a.k.a. SpecOS) by Paul Dunn, an
integrated development environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools a ...
(IDE) providing an enhanced superset of Sinclair BASIC -
Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
,
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
, Pandora, and
Raspberry Pi Raspberry Pi () is a series of small single-board computers (SBCs) developed in the United Kingdom by the Raspberry Pi Foundation in association with Broadcom. The Raspberry Pi project originally leaned towards the promotion of teaching basic ...
* '' ZX-Basicus'' by Juan-Antonio Fernández-Madrigal, a synthesizer, analyzer, optimizer, interpreter and debugger of Sinclair BASIC 48K for PCs, freely downloadable for
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
and
Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
.


See also

* * *


Notes


References


Bibliography

* * * *


External links


Sinclair ZX Spectrum BASIC Programming
The original 1982 manual by Steven Vickers (referenced above)
Sinclair ZX81 Basic Programming
: also by Vickers
The History of Sinclair BASIC
By Andrew Owen

Basic 64 user manual for Timex Computer 2048

A LL(1) grammar specification for parsing Sinclair BASIC 16/48K {{BASIC ZX Spectrum Sinclair Research BASIC interpreters Discontinued BASICs BASIC programming language family